﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using LGE;

namespace EggCatcher
{
    public class StartScreen : GameScreen
    {
        Texture2D backGround;
        Texture2D tabua;
        Texture2D eggTexture;

        float eggScale = 0f;
        int opt = 0;
        Vector2 option1pos = new Vector2(300, 375);
        Vector2 option2pos = new Vector2(300, 475);

        // Sounds
        string SFXSelectMove = "Sounds\\SelectMove";
        string SFXSelectPick = "Sounds\\SelectPick";
        string song = "Sounds\\Intro";

        public StartScreen()
            : base()
        {

        }

        public override void LoadContent()
        {
            eggTexture = Egg.GetRandomTexture();
            backGround = Engine.Load<Texture2D>("Images\\bg_startscreen");
            tabua = Engine.Load<Texture2D>("Images\\tabua");
            Engine.AddSFX(SFXSelectMove);
            Engine.AddSFX(SFXSelectPick);
            Engine.AddSong(song);
            Engine.PlaySong(song);
        }

        public override void Update(GameTime gameTime)
        {
            UpdateInput();
            eggScale = 1 + (float)(Math.Sin(gameTime.TotalGameTime.TotalSeconds * 5) / 10);
        }

        public void UpdateInput()
        {
            if (Input.ButtonPressed(Buttons.LeftThumbstickDown) || Input.KeyPressed(Keys.Down))
            {
                Engine.PlaySFX(SFXSelectMove);
                if (opt == 0)
                {
                    opt = 1;
                    eggTexture = Egg.GetRandomTexture();
                }
            }
            else if (Input.ButtonPressed(Buttons.LeftThumbstickUp) || Input.KeyPressed(Keys.Up))
            {
                Engine.PlaySFX(SFXSelectMove);
                if (opt == 1)
                {
                    opt = 0;
                    eggTexture = Egg.GetRandomTexture();
                }
            }
      

            if (Input.ButtonPressed(Buttons.Start) || Input.KeyPressed(Keys.Enter))
            {
                Engine.PlaySFX(SFXSelectPick);
                if (opt == 0)
                {
                    GameScreenManager.Pop();
                    GameScreenManager.Push(new PlayScreen());
                }
                else Engine.game.Exit();
            }
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(backGround, Vector2.Zero, Color.White);
            spriteBatch.Draw(eggTexture, opt == 0 ? option1pos : option2pos, null, Color.White, 0, new Vector2(eggTexture.Width / 2, eggTexture.Height / 2), eggScale, SpriteEffects.None, 0);
        }
    }
}
